<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 2017/7/5
 * Time: 下午2:35
 */
class GuildController extends AdminBaseController
{

    public function index(){
        $this->setTitle('家族统计');

        $filter = new PubFilter();
        $grid   = new PubGrid();

        $filter->addOsFilter()
            ->addServerFilter(true)
            ->addFilter('time_start', 'input', PubFunc::t('时间'), array('date' => 'day', 'value' => date('Y-m-d', strtotime('-31 day'))))
            ->addFilter('time_end', 'input', PubFunc::t('至'), array('date' => 'day', 'value' => date('Y-m-d', strtotime('-1 day'))))
            ->addExport();

        $params = $filter->get();

        $header = GuildService::indexHeader($params);
        $data   = GuildService::indexData($params);

        if($filter->isExport()){
            $filename = LibExcel::getFilename('家族统计', $params);
            LibExcel::exportCsv($header, $data, $filename);
        }else{
            $grid->addGrid($header, $data, array(
                'order' => array('RecDate', 'desc')
            ));

            $this->out['filter'] = $filter->show();
            $this->out['grid']   = $grid->show();
        }
    }

}